﻿using System;
using System.Data;
using System.Collections.Generic;
using RealTimePriceFetchService.Model;
namespace RealTimePriceFetchService.BLL
{
    /// <summary>
    /// 业务逻辑类StockTransferQueueBLL 的摘要说明。
    /// </summary>
    public class StockTransferQueueBLL
    {
        private readonly RealTimePriceFetchService.DAL.StockTransferQueueDAL dal = new RealTimePriceFetchService.DAL.StockTransferQueueDAL();
        public StockTransferQueueBLL()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(RealTimePriceFetchService.Model.StockTransferQueueModel model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(RealTimePriceFetchService.Model.StockTransferQueueModel model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {

            dal.Delete(ID);
        }

        /// <summary>
        /// 删除已复制数据
        /// </summary>
        public void Clear()
        {

            dal.Clear();
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RealTimePriceFetchService.Model.StockTransferQueueModel GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 得到第一个对象实体
        /// </summary>
        public RealTimePriceFetchService.Model.StockTransferQueueModel GetTopModel()
        {

            return dal.GetTopModel();
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<RealTimePriceFetchService.Model.StockTransferQueueModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<RealTimePriceFetchService.Model.StockTransferQueueModel> modelList = new List<RealTimePriceFetchService.Model.StockTransferQueueModel>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                RealTimePriceFetchService.Model.StockTransferQueueModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new RealTimePriceFetchService.Model.StockTransferQueueModel();
                    if (ds.Tables[0].Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[n]["ID"].ToString());
                    }
                    model.RealTimePrice = ds.Tables[0].Rows[n]["RealTimePrice"].ToString();
                    if (ds.Tables[0].Rows[n]["HasCopied"].ToString() != "")
                    {
                        if ((ds.Tables[0].Rows[n]["HasCopied"].ToString() == "1") || (ds.Tables[0].Rows[n]["HasCopied"].ToString().ToLower() == "true"))
                        {
                            model.HasCopied = true;
                        }
                        else
                        {
                            model.HasCopied = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

